import assert from 'assert'
import { parse } from 'parse5'
import findChild from '../index.js'

const html = `<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>parse5-find-child test example</title>
</head>

<body>
    <img class="top-image" src="boat.gif" alt="Big Boat">
    <form class="simple-form" id="profile" action="">
        <fieldset>
            <legend>Personal information:</legend>
            Name: <input type="text" size="30"><br>
            E-mail: <input type="text" size="30"><br>
            Date of birth: <input type="text" size="10">
        </fieldset>
    </form>
    <div class="list-wrapper" id="drink">
        <ul>
            <li>Coffee</li>
            <li>Milk</li>
        </ul>
    </div>
    <div class="list-wrapper2" id="fruit">
        <ul>
            <li>Banana</li>
            <li>Apple</li>
        </ul>
    </div>
    <div class="table-wrapper">
        <table id="contact" border="1">
            <tr>
                <th>First Name:</th>
                <td>Bill Gates</td>
            </tr>
            <tr>
                <th>Telephone:</th>
                <td>555 77 854</td>
            </tr>
            <tr>
                <th>Telephone:</th>
                <td>555 77 855</td>
            </tr>
        </table>
    </div>
</body>

</html>`

const doc = parse(html)
describe('given single fuzzy path', function () {
    it('should find 1 node through id name', async function () {
        const out = findChild(doc, '#contact')
        assert.equal(out.length, 1)
    })
    it('should find 1 node through class name', async function () {
        const out = findChild(doc, '.list-wrapper')
        assert.equal(out.length, 1)
    })
})

describe('given complex fuzzy path', function () {
    it('should find lots of nodes', async function () {
        const out = findChild(doc, '.list-wrapper2;*;<li>')
        assert.ok(out.length > 1)
    })
})
